package site.yunnong.atvris.portal.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import site.yunnong.atvris.common.api.ResultVO;
import site.yunnong.atvris.portal.service.OssService;
import site.yunnong.atvris.common.dto.OssCallbackResult;
import site.yunnong.atvris.common.dto.OssPolicyResult;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author JinghaoZhang
 * @date 2021年-04月-29日
 */
@Api(tags = "oss管理")
@RestController
@RequestMapping("/aliyun/oss")
public class OssController {

    @Resource
    private OssService ossService;

    @ApiOperation("上传签名生成")
    @GetMapping("/policy")
    public ResultVO policy() {
         OssPolicyResult result = ossService.policy();
         return new ResultVO().success(result);
    }
    
    @ApiOperation("oss上传回调")
    @PostMapping("/callback")
    public ResultVO callback(HttpServletRequest request) {
        OssCallbackResult result = ossService.callback(request);
        return new ResultVO().success(result);
    }
    
    @ApiOperation("oss删除文件")
    @PostMapping("/delete")
    public ResultVO delete(@RequestBody String objectName) {
        ossService.delete(objectName);
        return new ResultVO().success();
    }
}
